﻿namespace AnyOffice.general.mytable
{
    using AjaxPro;
    using AnyOffice.BIZ;
    using AnyOffice.Components;
    using AnyOffice.DAL;
    using log4net;
    using Microsoft.ApplicationBlocks.Data;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Web;
    using System.Reflection;

    public class AjaxMethods
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        [AjaxMethod]
        public string Attend()
        {
            StringBuilder builder = new StringBuilder();
            SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
            if (this.IsOnDuty()) builder.Append("个人考勤：<a href='/general/attend/personal/index.aspx'>上下班登记</a><br>");
            DataTable table = new AttendOutDao().SelectBack(connection, HttpContext.Current.User.Identity.Name);
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    builder.Append("个人考勤：<a href='/general/attend/personal/out.aspx'>外出归来</a><br>");
                }
            }
            DataTable table2 = new AttendLeaveDao().SelectDestroy(connection, HttpContext.Current.User.Identity.Name);
            if (table2.Rows.Count > 0)
            {
                for (int j = 0; j < table2.Rows.Count; j++)
                {
                    builder.Append("个人考勤：<a href='/general/attend/personal/leave.aspx'>申请销假</a><br>");
                }
            }
            DataTable table3 = new AttendEvectionDao().SelectBack(connection, HttpContext.Current.User.Identity.Name);
            if (table3.Rows.Count > 0)
            {
                for (int k = 0; k < table3.Rows.Count; k++)
                {
                    builder.Append("个人考勤：<a href='/general/attend/personal/evection.aspx'>出差归来</a><br>");
                }
            }
            table = new AttendOutDao().SelectAdmin(connection);
            if (table.Rows.Count > 0)
            {
                for (int m = 0; m < table.Rows.Count; m++)
                {
                    builder.Append("考勤管理：<a href='/general/attend/manage/index.aspx'>批示" + table.Rows[m]["UserName"].ToString() + "的外出申请</a><br>");
                }
            }
            table2 = new AttendLeaveDao().SelectAdmin(connection);
            if (table2.Rows.Count > 0)
            {
                for (int n = 0; n < table2.Rows.Count; n++)
                {
                    if (Convert.ToInt32(table2.Rows[n]["Allow"].ToString()) == 0)
                        builder.Append("考勤管理：<a href='/general/attend/manage/index.aspx'>批示" + table2.Rows[n]["UserName"].ToString() + "的请假申请</a><br>");
                    else if (Convert.ToInt32(table2.Rows[n]["Allow"].ToString()) == 3) builder.Append("考勤管理：<a href='/general/attend/manage/index.aspx'>批示" + table2.Rows[n]["UserName"].ToString() + "的销假申请</a><br>");
                }
            }
            table3 = new AttendEvectionDao().SelectAdmin(connection);
            if (table3.Rows.Count > 0)
            {
                for (int num6 = 0; num6 < table3.Rows.Count; num6++)
                {
                    builder.Append("考勤管理：<a href='/general/attend/manage/index.aspx'>批示" + table3.Rows[num6]["UserName"].ToString() + "的出差申请</a><br>");
                }
            }
            connection.Close();
            return builder.ToString();
        }

        [AjaxMethod]
        public string GetEmail()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                DataTable table = new EmailDao().SelectMyTable(connection, HttpContext.Current.User.Identity.Name);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        builder.Append("\x00b7");
                        builder.Append("<a href=\"/general/email/inbox_read_email.aspx?email_id=" + table.Rows[i]["EmailId"].ToString() + "&box_id=" + table.Rows[i]["BoxId"].ToString() + "&page=1\">");
                        if (table.Rows[i]["Subject"].ToString() != string.Empty)
                            builder.Append(table.Rows[i]["Subject"].ToString());
                        else
                            builder.Append("[无主题]");
                        builder.Append("</a> ");
                        builder.Append("<u title=\"部门：" + table.Rows[i]["DeptName"].ToString() + "\" style=\"cursor:hand\">" + table.Rows[i]["UserName"].ToString() + "</u>");
                        if (!Convert.ToBoolean(table.Rows[i]["ReadFlag"].ToString())) builder.Append("<img src=/images/email_new.gif alt=未读 align=absmiddle>");
                        builder.Append("<br>");
                    }
                }
                else
                    builder.Append("\x00b7暂无内部邮件");
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
            return builder.ToString();
        }

        [AjaxMethod]
        public string GetNews()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                NewsDao dao = new NewsDao();
                UserCache cache = new UserCache();
                DataTable table = dao.SelectMyTable(connection, cache.DeptId, cache.PrivId, cache.UserId);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        builder.Append("\x00b7");
                        builder.Append("<a href=\"javascript:open_news(" + table.Rows[i]["NewsId"].ToString() + ");\">");
                        builder.Append("【" + table.Rows[i]["TypeName"].ToString() + "】");
                        builder.Append(table.Rows[i]["Subject"].ToString());
                        builder.Append("</a>&nbsp;&nbsp;");
                        builder.Append("<a href=\"javascript:re_news('" + table.Rows[i]["NewsId"].ToString() + "');\" style=\"TEXT-DECORATION:underline\">评论</a>&nbsp;");
                        builder.Append("(" + Convert.ToDateTime(table.Rows[i]["SendTime"].ToString()).ToString("d") + ")");
                        if (table.Rows[i]["Readers"] == DBNull.Value)
                            builder.Append("<img src=/images/new.gif align=absmiddle>");
                        else if (("," + table.Rows[i]["Readers"].ToString() + ",").IndexOf("," + cache.UserId + ",") < 0) builder.Append("<img src=/images/new.gif align=absmiddle>");
                        builder.Append("<br>");
                    }
                }
                else
                    builder.Append("\x00b7暂无新闻");
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
            return builder.ToString();
        }

        [AjaxMethod]
        public string GetNotify()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                NotifyDao dao = new NotifyDao();
                UserCache cache = new UserCache();
                DataTable table = dao.SelectMyTable(connection, cache.DeptId, cache.PrivId, cache.UserId);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        builder.Append("\x00b7");
                        builder.Append("<a href=\"javascript:open_notify(" + table.Rows[i]["NotifyId"].ToString() + ");\">");
                        if (Convert.ToBoolean(table.Rows[i]["Important"].ToString()))
                            builder.Append("<span style=\"font-weight: bold;color: #FF0000;\">");
                        else
                            builder.Append("<span>");
                        builder.Append("【" + table.Rows[i]["TypeName"].ToString() + "】");
                        builder.Append(table.Rows[i]["Subject"].ToString());
                        builder.Append("</span></a>");
                        builder.Append("(" + Convert.ToDateTime(table.Rows[i]["SendTime"].ToString()).ToString("d") + ")");
                        if (table.Rows[i]["Readers"] == DBNull.Value)
                            builder.Append("<img src=/images/new.gif align=absmiddle>");
                        else if (("," + table.Rows[i]["Readers"].ToString() + ",").IndexOf("," + cache.UserId + ",") < 0) builder.Append("<img src=/images/new.gif align=absmiddle>");
                        builder.Append("<br>");
                    }
                }
                else
                    builder.Append("\x00b7暂无公告通知");
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
            return builder.ToString();
        }

        [AjaxMethod]
        public string GetVote()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                VoteDao dao = new VoteDao();
                UserCache cache = new UserCache();
                DataTable table = dao.SelectMyTable(connection, cache.DeptId);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        builder.Append("\x00b7");
                        builder.Append("<a href=\"javascript:open_vote(" + table.Rows[i]["VoteId"].ToString() + ");\">");
                        builder.Append(table.Rows[i]["Subject"].ToString());
                        builder.Append("</a>");
                        builder.Append("<br>");
                    }
                }
                else
                    builder.Append("\x00b7暂无投票");
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
            return builder.ToString();
        }

        [AjaxMethod]
        public string GetWork()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                DataTable table = new WorkFlowBiz().MyTable(connection, HttpContext.Current.User.Identity.Name);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        builder.Append("工作流：");
                        if (Convert.ToInt32(table.Rows[i]["PrcsFlag"].ToString()) == 1)
                            builder.Append("<IMG alt='未接收' src='/images/email_close.gif' align='absMiddle'>");
                        else
                            builder.Append("<IMG alt='已接收' src='/images/email_open.gif' align='absMiddle'>");
                        builder.Append("<a href=\"/general/workflow/list/flow_input.aspx?run_id=" + table.Rows[i]["RunId"].ToString() + "&prcs_id=" + table.Rows[i]["PrcsId"].ToString() + "\">");
                        builder.Append(table.Rows[i]["FlowName"].ToString() + " - " + table.Rows[i]["RunName"].ToString());
                        builder.Append("</a>");
                        builder.Append("<br>");
                    }
                }
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
            return builder.ToString();
        }

        [AjaxMethod]
        public string GetWorkplan()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                UserCache cache = new UserCache();
                DataTable table = new PlanWorkDao().Today(connection, cache.DeptId);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        builder.Append("\x00b7");
                        builder.Append("<a href=\"javascript:open_workplan(" + table.Rows[i]["PlanId"].ToString() + ");\">");
                        builder.Append(table.Rows[i]["Name"].ToString());
                        builder.Append("</a>");
                        builder.Append("<br>");
                    }
                }
                else
                    builder.Append("\x00b7暂无计划");
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
            return builder.ToString();
        }

        private bool IsOnDuty()
        {
            try
            {
                int num = 30;
                int num2 = 10;
                int num3 = 10;
                int num4 = 60;
                string str = string.Empty;
                AttendParaDao dao = new AttendParaDao();
                dao.GetPara();
                 
                num = dao.DutyIntervalBefore1;
                num2 = dao.DutyIntervalAfter1;
                num3 = dao.DutyIntervalBefore2;
                num4 = dao.DutyIntervalAfter2;
                
                if (dao.NoDutyUser != string.Empty) str = "," + dao.NoDutyUser + ",";
                if (str.IndexOf("," + HttpContext.Current.User.Identity.Name + ",") < 0)
                {
                    int num5;
                    DateTime time;
                    DateTime time2;
                    DateTime time3;
                    if (new AttendHolidayDao().IsHoliday(DateTime.Now)) return false;
                    SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                    DataTable userConfig = new AttendConfigDao().GetUserConfig(connection, HttpContext.Current.User.Identity.Name);
                    connection.Close();
                    string str2 = (userConfig.Rows[0]["General"] != DBNull.Value) ? userConfig.Rows[0]["General"].ToString() : "";
                    if (str2 != string.Empty) str2 = "," + str2 + ",";
                    int dayOfWeek = (int) DateTime.Now.DayOfWeek;
                    if (str2.IndexOf("," + dayOfWeek.ToString() + ",") >= 0) return false;
                    DataTable table2 = new DataTable();
                    table2.Columns.Add("No", Type.GetType("System.Int32"));
                    table2.Columns.Add("DutyType", Type.GetType("System.Int32"));
                    table2.Columns.Add("BeginTime", Type.GetType("System.DateTime"));
                    table2.Columns.Add("EndTime", Type.GetType("System.DateTime"));
                    if (userConfig.Rows[0]["DutyTime1"] != DBNull.Value)
                    {
                        num5 = Convert.ToInt32(userConfig.Rows[0]["DutyType1"].ToString());
                        time = Convert.ToDateTime(DateTime.Now.ToString("d") + " " + userConfig.Rows[0]["DutyTime1"].ToString());
                        if (num5 == 1)
                        {
                            time2 = time.AddMinutes((double) -num);
                            time3 = time.AddMinutes((double) num2);
                        }
                        else
                        {
                            time2 = time.AddMinutes((double) -num3);
                            time3 = time.AddMinutes((double) num4);
                        }
                        table2.Rows.Add(new object[] { 1, num5, time2, time3 });
                    }
                    if (userConfig.Rows[0]["DutyTime2"] != DBNull.Value)
                    {
                        num5 = Convert.ToInt32(userConfig.Rows[0]["DutyType2"].ToString());
                        time = Convert.ToDateTime(DateTime.Now.ToString("d") + " " + userConfig.Rows[0]["DutyTime2"].ToString());
                        if (num5 == 1)
                        {
                            time2 = time.AddMinutes((double) -num);
                            time3 = time.AddMinutes((double) num2);
                        }
                        else
                        {
                            time2 = time.AddMinutes((double) -num3);
                            time3 = time.AddMinutes((double) num4);
                        }
                        table2.Rows.Add(new object[] { 2, num5, time2, time3 });
                    }
                    if (userConfig.Rows[0]["DutyTime3"] != DBNull.Value)
                    {
                        num5 = Convert.ToInt32(userConfig.Rows[0]["DutyType3"].ToString());
                        time = Convert.ToDateTime(DateTime.Now.ToString("d") + " " + userConfig.Rows[0]["DutyTime3"].ToString());
                        if (num5 == 1)
                        {
                            time2 = time.AddMinutes((double) -num);
                            time3 = time.AddMinutes((double) num2);
                        }
                        else
                        {
                            time2 = time.AddMinutes((double) -num3);
                            time3 = time.AddMinutes((double) num4);
                        }
                        table2.Rows.Add(new object[] { 3, num5, time2, time3 });
                    }
                    if (userConfig.Rows[0]["DutyTime4"] != DBNull.Value)
                    {
                        num5 = Convert.ToInt32(userConfig.Rows[0]["DutyType4"].ToString());
                        time = Convert.ToDateTime(DateTime.Now.ToString("d") + " " + userConfig.Rows[0]["DutyTime4"].ToString());
                        if (num5 == 1)
                        {
                            time2 = time.AddMinutes((double) -num);
                            time3 = time.AddMinutes((double) num2);
                        }
                        else
                        {
                            time2 = time.AddMinutes((double) -num3);
                            time3 = time.AddMinutes((double) num4);
                        }
                        table2.Rows.Add(new object[] { 4, num5, time2, time3 });
                    }
                    if (userConfig.Rows[0]["DutyTime5"] != DBNull.Value)
                    {
                        num5 = Convert.ToInt32(userConfig.Rows[0]["DutyType5"].ToString());
                        time = Convert.ToDateTime(DateTime.Now.ToString("d") + " " + userConfig.Rows[0]["DutyTime5"].ToString());
                        if (num5 == 1)
                        {
                            time2 = time.AddMinutes((double) -num);
                            time3 = time.AddMinutes((double) num2);
                        }
                        else
                        {
                            time2 = time.AddMinutes((double) -num3);
                            time3 = time.AddMinutes((double) num4);
                        }
                        table2.Rows.Add(new object[] { 5, num5, time2, time3 });
                    }
                    if (userConfig.Rows[0]["DutyTime6"] != DBNull.Value)
                    {
                        num5 = Convert.ToInt32(userConfig.Rows[0]["DutyType6"].ToString());
                        time = Convert.ToDateTime(DateTime.Now.ToString("d") + " " + userConfig.Rows[0]["DutyTime6"].ToString());
                        if (num5 == 1)
                        {
                            time2 = time.AddMinutes((double) -num);
                            time3 = time.AddMinutes((double) num2);
                        }
                        else
                        {
                            time2 = time.AddMinutes((double) -num3);
                            time3 = time.AddMinutes((double) num4);
                        }
                        table2.Rows.Add(new object[] { 6, num5, time2, time3 });
                    }
                    string str3 = "SELECT * FROM [dbo].[Attend_Duty] WHERE [UserId] = '" + HttpContext.Current.User.Identity.Name + "' AND [RegisterTime] >='" + DateTime.Now.ToString("d") + " 00:00:00' AND [RegisterTime] <= '" + DateTime.Now.ToString("d") + " 23:59:59'";
                    connection = new SqlConnection(ConfigManager.ConnectionString);
                    DataTable table3 = SqlHelper.ExecuteDataset(connection, CommandType.Text, str3).Tables[0];
                    connection.Close();
                    for (int i = 0; i < table2.Rows.Count; i++)
                    {
                        if (table3.Select("RegisterType = " + table2.Rows[i]["DutyType"].ToString() + " AND RegisterTime >='" + table2.Rows[i]["BeginTime"].ToString() + "' AND RegisterTime <='" + table2.Rows[i]["EndTime"].ToString() + "'").Length == 0 && Convert.ToDateTime(table2.Rows[i]["BeginTime"].ToString()) <= DateTime.Now && DateTime.Now <= Convert.ToDateTime(table2.Rows[i]["EndTime"].ToString())) return true;
                    }
                }
                return false;
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
                return false;
            }
        }

        [AjaxMethod]
        public string Out()
        {
            StringBuilder builder = new StringBuilder();
            try
            {
                DateTime time = Convert.ToDateTime(DateTime.Now.ToString("d") + " 00:00:00");
                DateTime time2 = Convert.ToDateTime(DateTime.Now.ToString("d") + " 23:59:59");
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                string str = "SELECT [Attend_Evection].[EvectionDest],[Attend_Evection].[EvectionDate1],[Attend_Evection].[EvectionDate2],[Attend_Evection].[Status],[Users].[UserName],[Department].[DeptName] FROM [dbo].[Attend_Evection],[dbo].[Users],[dbo].[Department] WHERE [Attend_Evection].[Allow] = 1 AND [Attend_Evection].[Status] = 0 AND [Attend_Evection].[UserId] = [Users].[UserId] AND [Users].[DeptId] = [Department].[DeptId] AND ([Attend_Evection].[EvectionDate1] <= '" + DateTime.Now.ToString("d") + "' AND [Attend_Evection].[EvectionDate2] >= '" + DateTime.Now.ToString("d") + "') ORDER BY [Attend_Evection].[EvectionId] ASC";

                DataTable table = SqlHelper.ExecuteDataset(connection, CommandType.Text, str).Tables[0];
                if (table.Rows.Count > 0)
                {
                    builder.Append("<fieldset class='small'>");
                    builder.Append(" <legend align=left>");
                    builder.Append("  <b>出差人员</b>");
                    builder.Append("</legend>");
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        builder.Append("<u title='部门：" + table.Rows[i]["DeptName"].ToString() + " " + Convert.ToDateTime(table.Rows[i]["EvectionDate1"].ToString()).ToString("d") + " 至 " + Convert.ToDateTime(table.Rows[i]["EvectionDate2"].ToString()).ToString("d") + " 地点：" + table.Rows[i]["EvectionDest"].ToString() + "' style='cursor:hand'>" + table.Rows[i]["UserName"].ToString() + "</u> ");
                    }
                    builder.Append("</fieldset>");
                }
                str = "SELECT [Attend_Leave].[LeaveType],[Attend_Leave].[LeaveDate1],[Attend_Leave].[LeaveDate2],[Attend_Leave].[Status],[Users].[UserName],[Department].[DeptName] FROM [dbo].[Attend_Leave],[dbo].[Users],[dbo].[Department] WHERE [Attend_Leave].[Allow] = 1 AND [Attend_Leave].[Status] = 1 AND [Attend_Leave].[UserId] = [Users].[UserId] AND [Users].[DeptId] = [Department].[DeptId] AND (([Attend_Leave].[LeaveDate1] >= '" + time.ToString() + "' AND [Attend_Leave].[LeaveDate1] <= '" + time2.ToString() + "') OR ([Attend_Leave].[LeaveDate2] >= '" + time.ToString() + "' AND [Attend_Leave].[LeaveDate2] <= '" + time2.ToString() + "')) ORDER BY [Attend_Leave].[LeaveId] ASC";
                DataTable table2 = SqlHelper.ExecuteDataset(connection, CommandType.Text, str).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    builder.Append("<fieldset class='small'>");
                    builder.Append(" <legend align=left>");
                    builder.Append("  <b>请假人员</b>");
                    builder.Append("</legend>");
                    for (int j = 0; j < table2.Rows.Count; j++)
                    {
                        builder.Append("<u title='部门：" + table2.Rows[j]["DeptName"].ToString() + " " + table2.Rows[j]["LeaveDate1"].ToString() + " 至 " + table2.Rows[j]["LeaveDate2"].ToString() + "' style='cursor:hand'>" + table2.Rows[j]["UserName"].ToString() + "</u> ");
                    }
                    builder.Append("</fieldset>");
                }
                str = "SELECT [Attend_Out].[OutType],[Attend_Out].[OutTime1],[Attend_Out].[OutTime2],[Attend_Out].[Status],[Users].[UserName],[Department].[DeptName] FROM [dbo].[Attend_Out],[dbo].[Users],[dbo].[Department] WHERE [Attend_Out].[Allow] = 1 AND [Attend_Out].[Status] = 0 AND [Attend_Out].[UserId] = [Users].[UserId] AND [Users].[DeptId] = [Department].[DeptId] AND (([Attend_Out].[OutTime1] >= '" + time.ToString() + "' AND [Attend_Out].[OutTime1] <= '" + time2.ToString() + "') OR ([Attend_Out].[OutTime2] >= '" + time.ToString() + "' AND [Attend_Out].[OutTime2] <= '" + time2.ToString() + "')) ORDER BY [Attend_Out].[OutId] ASC";
                DataTable table3 = SqlHelper.ExecuteDataset(connection, CommandType.Text, str).Tables[0];
                if (table3.Rows.Count > 0)
                {
                    builder.Append("<fieldset class='small'>");
                    builder.Append(" <legend align=left>");
                    builder.Append("  <b>外出人员</b>");
                    builder.Append("</legend>");
                    for (int k = 0; k < table3.Rows.Count; k++)
                    {
                        builder.Append("<u title='部门：" + table3.Rows[k]["DeptName"].ToString() + " " + Convert.ToDateTime(table3.Rows[k]["OutTime1"].ToString()).ToString("HH:mm") + " 至 " + Convert.ToDateTime(table3.Rows[k]["OutTime2"].ToString()).ToString("HH:mm") + "' style='cursor:hand'>" + table3.Rows[k]["UserName"].ToString() + "</u> ");
                    }
                    builder.Append("</fieldset>");
                }
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
            return builder.ToString();
        }

        [AjaxMethod]
        public void SetNote(string note)
        {
            try
            {
                SqlConnection connection = new SqlConnection(ConfigManager.ConnectionString);
                string str = "UPDATE [dbo].[Users] SET [Note] = @Note WHERE [UserId] = @UserId";
                SqlParameter[] parameterArray = new SqlParameter[2];
                parameterArray[0] = new SqlParameter("@UserId", SqlDbType.NVarChar, 20);
                parameterArray[0].Value = HttpContext.Current.User.Identity.Name;
                parameterArray[1] = new SqlParameter("@Note", SqlDbType.NText);
                parameterArray[1].Value = note;
                SqlHelper.ExecuteNonQuery(connection, CommandType.Text, str, parameterArray);
                connection.Close();
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled) log.Error("", exception);
            }
        }
    }
}

